<template>
  <div class="power__wrap">
    <h4 class="power__title">
      <svg-icon iconClass="energy" :size="20"/>
      <span>能量扣费方式</span>
    </h4>

  <div class="power__list_content">
      <div class="list__item list__head">
        <p>AI创作使用的模型或工具</p>
        <p>每1000tokens消耗能量
          <el-tooltip
            placement="top"
            :open-delay="300"
            effect="light"
          >
            <template slot="content">
              <div class="tooltip-content" style="color: #000;max-width: 500px;">
                <div class="title">什么是token?</div>
                <div class="text">在自然语言处理中，token是指一段自然语言文本分解成的最小语法单元，例如单词、标点符号、数字等。它可以使计算机更好地理解和处理自然语言文本。每个token 通常是一个字节序列，可以表示一个或多个字符。不同的语言和字符可能占用不同数量的 token。具体来讲，在英文中，一个单词大约占用 0.75个 token， 一个中文字符可能占用一个或两个token。</div>
              </div>
            </template>
            <svg-icon iconClass="question" :size="20" class="icon"/>
          </el-tooltip>
        </p>
      </div>
      <div v-for="item in list" :key="item.fn_id" class="list__item">
        <p>
          <span>{{ item.name }}</span>
        </p>
        <p>
          <span>{{ item.price }}</span>
        </p>
      </div>
    </div>
  </div>
</template>
<script>
import { getFnListApi } from '@/api/energy'
export default {
  name: 'energyRule',
  props: {
    data: {
      type: Array
    }
  },
  data () {
    return {
      fnList: []
    }
  },
  computed: {
    list () {
      return this.data || this.fnList
    }
  },
  created () {
    if (!this.data) {
      this.getFnList()
    }
  },
  methods: {
    getFnList () {
      getFnListApi()
        .then(res => {
          this.fnList = (res.data?.list || []).map(({ price, name, fn_id }) => ({ price, name, fn_id }))
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.power__wrap {
  padding: 0 23px;
  margin: 5px 0 0;
}
.power__title {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  gap: 6px;
  border-bottom: 1px solid rgba($color: #fff, $alpha: 0.1);
  margin-bottom: 20px;
  font-weight: bold;
  font-size: 16px;
  color: #FFFFFF;
}
.list__item {
  display: flex;
  align-items: stretch;
  p {
    flex: 1;
    padding: 14px 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-sizing: border-box;
    border: 1px solid rgba($color: #fff, $alpha: 0.1);
    border-top: 0;
    border-right: 0;
    line-height: 1.2;
    text-align: center;
    font-size: 14px;
    &:nth-of-type(1) {
      background: rgba(255, 255, 255, 0.05);
    }
    &:nth-of-type(2) {
      color: rgba(203, 136, 255, 1);
      background: rgba(203, 136, 255, 0.05);
    }
    span {
      line-height: 1.57;
    }
    .icon {
      cursor: pointer;
    }
  }
}
div.list__item:last-of-type {
  p:nth-of-type(1) {
    border-bottom-left-radius: 10px;
  }
  p:last-of-type {
    border-bottom-right-radius: 10px;
  }
}
.list__head {
  p {
    font-weight: bold;
    font-size: 16px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    padding: 15px;
  }
  p:nth-of-type(1) {
    background: rgba(255, 255, 255, 0.1);
  }
  p:nth-of-type(2) {
    background: rgba(203, 136, 255, 0.1);
  }
}
.tooltip-content{
  max-width: 300px;
  color: #000;
  .title {
    margin-bottom: 10px;
    font-weight: 700;
  }
  .text {
    line-height: 20px;
    font-size: 12px;
  }
}
</style>
